/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.pdx.cs.guavadata.query;

import edu.pdx.cs.guavadata.Channel;
import edu.pdx.cs.guavadata.Transform;
import edu.pdx.cs.guavadata.domain.Domain;
import java.util.ArrayList;

/**
 *
 * @author VuTran
 */
public class CrossJoin extends Operator {

    Operator child1;
    Operator child2;

    public Operator getChild1() {
        return child1;
    }

    public void setChild1(Operator child1) {
        this.child1 = child1;
    }

    public Operator getChild2() {
        return child2;
    }

    public void setChild2(Operator child2) {
        this.child2 = child2;
    }

    public CrossJoin(Operator child1, Operator child2) {
        this.child1 = child1;
        this.child2 = child2;
        child1.parent = this;
        child2.parent = this;

        // list of column and domains is equal to the combination of the two from the base expressions
        this.exposedColumns = new ArrayList<String>(this.child1.exposedColumns);
        this.exposedColumns.addAll(this.child2.exposedColumns);
        this.exposedDomains = new ArrayList<Domain>(this.child1.exposedDomains);
        this.exposedDomains.addAll(this.child2.exposedDomains);

    }
    
    
    @Override
    public boolean isQuery() {
        return false;
    }

    @Override
    public SqlText visit(Provider qv) {
        return qv.transform(this);
    }

    @Override
    public void visit(Channel c, String table) {
        c.mapAliases(this, table);
    }

    @Override
    public void visit(Transform t, Command c) {
        t.expand(this, c);
    }

    @Override
    public void notifyChange(Operator old, Operator newOp) {
        if (this.child1 == old) {
            this.child1 = newOp;
            newOp.parent = this;
        }
        if (this.child2 == old) {
            this.child2 = newOp;
            newOp.parent = this;
        }
    }

    @Override
    public Operator clone() {
        return new CrossJoin(this.child1.clone(), this.child2.clone());
    }

}
